package com.mazj.converter;


import org.springframework.core.convert.converter.Converter;
import org.springframework.format.support.FormattingConversionServiceFactoryBean;

import java.text.SimpleDateFormat;

public class DateConverter implements Converter<String,Object> {

    /**
     * 将字符串转换成日期格式
     * @param source
     * @return
     */
    @Override
    public Object convert(String source) {
        try{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            sdf.setLenient(false);// 设置是否宽松解析:默认false
            return sdf.parse(source);
        }catch(Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
